// backend/app.js
const express = require('express');
const app = express();
const port = 3000;

// 解析 JSON 数据
app.use(express.json());

// 处理跨域问题
app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
    next();
});

// 引入 API 路由
const dataRouter = require('./api/data');
const userRouter = require('./api/user');
const userInfoRouter = require('./api/userInfo.js')
const activityRouter = require('./api/activety.js')
const todoRouter = require('./api/todoList.js'); 
const addAvaterRouter = require('./api/addAvater.js')
// 将 API 路由挂载到 /api 路径下
app.use('/api', dataRouter);
app.use('/api', userRouter);
app.use('/api', userInfoRouter);
app.use('/api', activityRouter);
app.use('/api/todo',todoRouter);
app.use('/api',addAvaterRouter);
// 启动服务器
app.listen(port, () => {
    console.log(`服务器运行在 http://localhost:${port}`);
});